<template>
  <el-form class="login">
    <div class="loginTitle">
      <text>驾校系统欢迎您</text>
    </div>
    <div class="myInput">
      <el-icon style="width: 2em; height: 2em; margin-right: 5px"
        ><User
      /></el-icon>
      <span>账号：</span>
      <el-input class="list" v-model="dataFrom.username"></el-input>
    </div>
    <div class="myInput">
      <el-icon style="width: 2em; height: 2em; margin-right: 5px"
        ><Check
      /></el-icon>
      <span>密码：</span>
      <el-input class="list" password v-model="dataFrom.password"></el-input>
    </div>
    <el-button class="loginBtn" @click="login" type="primary"> 登入 </el-button>
  </el-form>
</template>
<script lang="js" setup>
import request from '@/util/request';
import {ref} from 'vue'
import router from '@/router';
    let dataFrom= ref({
		username: "",
		password: "",
	})
  let userData
    function test(){
        console.log(dataFrom.value.username)
    }
    function login(){
        console.log(dataFrom.value.username,dataFrom.value.password)
        let s={userName:dataFrom.value.username,userPwd:dataFrom.value.password}
      //网络请求
      request.post('/api/user/login?userName='+dataFrom.value.username+'&passWord='+dataFrom.value.password).then(res=>{
        console.log(res)
        if(res.success===true){
			request.post('/api/user/getByAccount?userAccount='+dataFrom.value.username).then(res=>{
        userData=res.data
        console.log(userData)
				localStorage.setItem('data',JSON.stringify(res.data))
        switch(userData.userType){
             case 1 ://教练
              router.push('/mycourse')
              break;
              case 2 ://学生
                request.post("api/student/getByuserId?userId="+res.data.userId).then(res=>{
                  if(res.data.sAccept===0){
                    router.push('enroll')
                  }else{
                    router.push('/course')
                  }
                })
              break;
              case 3 ://管理员
              router.push('/student')
              break;
      } 
			})
        }
      })
    }
</script>

<style scoped>
.login {
  width: 600px;
  background-color: #fff;
  border: 10px solid #fff;
  border-radius: 20px;
  box-sizing: border-box;
  box-shadow: 0 0 8px #eeeeee;
}

.login .loginTitle {
  text-align: center;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  margin-bottom: 20rpx;
  padding: 28rpx 0;
}

.login .loginTitle text {
  color: #1e9fff;
  font-size: 40px;
  font-weight: bold;
}
.myInput {
  margin: 5px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: row;
}
.myInput span {
  width: 80px;
  font-size: 20px;
  text-align: center;
}
</style>
